<template>
    <div class="auth-container">
        <div class="auth-card">
            <div class="auth-tabs">
                <button @click="activeTab = 'login'" :class="{ active: activeTab === 'login' }">登录</button>
                <button @click="activeTab = 'register'" :class="{ active: activeTab === 'register' }">注册</button>
            </div>
            <transition name="fade" mode="out-in">
                <LoginForm v-if="activeTab === 'login'" @success="handleLoginSuccess" />
                <RegisterForm v-else @success="handleRegisterSuccess" />
            </transition>
        </div>
    </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { useRouter } from 'vue-router';
import LoginForm from '../components/LoginForm.vue';
import RegisterForm from '../components/RegisterForm.vue';

const activeTab = ref < 'login' | 'register' > ('login');
const router = useRouter();
const handleLoginSuccess = () => {
  router.replace('/welcome');
};
const handleRegisterSuccess = () => {
    activeTab.value = 'login';
};
</script>

<style scoped>
.auth-container {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    background: rgba(0, 0, 0, 0.5);
}

.auth-card {
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(10px);
    border-radius: 12px;
    padding: 2rem;
    width: 400px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}

.auth-tabs {
    display: flex;
    gap: 1rem;
    margin-bottom: 2rem;
}

.auth-tabs button {
    flex: 1;
    padding: 0.8rem;
    border: none;
    background: rgba(109, 213, 250, 0.1);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.auth-tabs button.active {
    background: #6DD5FA;
    color: white;
}

.fade-enter-active,
.fade-leave-active {
    transition: opacity 0.3s ease;
}

.fade-enter-from,
.fade-leave-to {
    opacity: 0;
}
</style>